<?php

namespace SunAdmin\Common;

class ResponseJson
{
    public static function success($data = null, $msg = '操作成功', $code = 200)
    {
        return json([
            'code' => $code,
            'message' => $msg,
            'data' => $data,
        ]);
    }

    public static function error($msg = '操作失败', $code = 500, $data = null)
    {
        $res = [
            'code' => $code,
            'message' => $msg,
            'data' => $data,
        ];
        if (!$data){
            unset($res['data']);
        }
        return json($res);
    }
} 